package chapter4;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.*;

public class MouseKey  extends Composite{

	Label output;
	private Listener UntypedListener = new Listener() {

		@Override
		public void handleEvent(Event event) {
			switch (event.type) {
			case SWT.MouseEnter:
				output.setText("mouse enter");
				break;
			case SWT.MouseExit:
				output.setText("mouse exit");
				break;

			default:
				break;
			}
		}
		
	};

	public MouseKey(Composite parent) {
		super(parent, SWT.NULL);

		Button typed = new Button(this, SWT.PUSH);
		typed.setText("typed");		
		typed.setLocation(2, 10);
		typed.pack();

		typed.addKeyListener(new KeyAdapter()
		{
			@Override
			public void keyPressed(KeyEvent e) {
				keyHandler();
			}

			private void keyHandler() {
				output.setText("key event");
			}			
		}
		);
		
		Button untyped = new Button(this, SWT.PUSH);
		untyped.setText("untyped");
		untyped.setLocation(80, 10);
		untyped.pack();
		
		untyped.addListener(SWT.MouseEnter, UntypedListener);
		untyped.addListener(SWT.MouseExit, UntypedListener );
		
		output = new Label(this, SWT.SHADOW_OUT);
		output.setBounds(40, 70, 90, 40);
		output.setText("no event");
		
		pack();		
	}



}
